@extends('layouts.app', ['active' => 6])

@section('title')人员回收站 -
@endsection

@section('content')
    <?php
    extract($filter);
    ?>

            <div class="panel panel-default">
                <div class="panel-heading"><i class="fa fa-trash-o"></i> 人员回收站
                    @include('person.menu',['active' => 3])
                </div>
                <div class="panel-body" id="person_list">
                  <div class="row" style="margin-bottom:10px">
                    <div class="col-md-4 text-left">
                      <form class="form-inline" action="{{ url('person/') }}" method="POST">
                          <button type="button" id="recover_button" data-toggle="modal" class="btn btn-default btn-sm" data-action="{{ url('person/recover') }}" data-target="#recover_modal"><i class="fa fa-undo" aria-hidden="true"></i> 还原</button>
                        <button type="button" id="delete_button" data-toggle="modal" class="btn btn-default btn-sm" data-action="{{ url('person/delete') }}" data-target="#delete_modal"><i class="fa fa-times" aria-hidden="true" style="color:darkred"></i> 彻底删除</button>

                      </form>

                    </div>

                      <div class="col-md-8 text-right">
                          <button type="button" class="btn btn-default invisible">&nbsp;</button>

                          共 <strong>{{$persons->total()}} </strong>人，每页
                          <select id="per_page" class="input-sm">
                              <option value="15" @if ($per_page == 15) selected="selected"@endif>15</option>
                              <option value="20" @if ($per_page == 20) selected="selected"@endif>20</option>
                              <option value="50" @if ($per_page == 50) selected="selected"@endif>50</option>
                              <option value="100" @if ($per_page == 100) selected="selected"@endif>100</option>
                          </select>
                      </div>
                          <!--
                        <form class="form-inline" action="" method="GET">
                          <div class="form-group">
                            <label class="sr-only" for="keyword">手机号</label>
                              <button type="button" class="btn btn-default" onclick="window.location.href='{{ url('person/') }}'">重置</button>
                              <input type="text" class="form-control" name="start_time" readonly="readonly" value="{{$filter['start_time']}}"id="start_time" size="8" placeholder="开始时间">
                              <input type="text" class="form-control" name="end_time" readonly="readonly" value="{{$filter['end_time']}}"id="end_time" size="8"  placeholder="结束时间">
                            <input type="text" class="form-control" name="keyword" value="{{$filter['keyword']}}"id="keyword" placeholder="姓名 | 手机号 | 身份证号">
                              <select name="is_the_city" class="form-control">
                                  <option value="" @if ($filter['is_the_city'] === '') selected="selected"@endif>所有</option>
                                  <option value="1" @if ($filter['is_the_city']  === 1) selected="selected"@endif>本市</option>
                                  <option value="0" @if ($filter['is_the_city']  === 0) selected="selected"@endif>他市</option>
                              </select>
                          </div>
                          <button type="submit" class="btn btn-default">搜索</button>

                        </form>
                        -->
                              <!--
                              <button type="submit" class="btn btn-primary modal_destroy_all" data-toggle="modal"  data-target="#destroy_all_modal">清空回收站</button>
                              -->
                      </div>


                    @if ($persons->total() != 0)
                  <table class="table table-hover table-striped table-condensed table-bordered">
                        <thead class="">
                          <tr>
                            <th><input type="checkbox" id="select_all"/></th>
                              <th>ID</th>
                            <th>照片</th>
                            <th>姓名</th>
                              <th>本市户籍</th>
                            <th>身份证</th>
                            <th>户籍地</th>
                            <th>到我市时间</th>
                            <th>手机号</th>
                            <th style="width:160px;text-align:center">操作</th>
                          </tr>
                        </thead>
                        <tbody>
                          @foreach ($persons as $person)
                          <tr>
                            <td><input type="checkbox" name="ids" value="{{ $person->id }}"/></td>
                              <td>
                                  {{ $person->id }}
                              </td>
                            <td>
                                <a>
                                    <img src="{{ url('/') }}/@if ($person->avatar != ''){{ $person->avatar }}@else{{  'img/avatar_default.png' }}@endif" style="overflow: hidden; height:30px;width:30px;border-radius:15px;border:1px solid #ccc;padding:3px" class="img-thumbnail" alt="{{ $person->name }}">
                                </a>
                            </td>
                            <td>{{ $person->name }}</td>
                              <td>@if ($person->is_the_city == 1)<strong style="color:#5cb85c">✔</strong> @else <strong style="color:#d9534f">✘</strong>@endif</td>
                            <td>{{ $person->id_number }}</td>
                            <td>{{ $person->reg_addr }}</td>
                              <td>{{ $person->five_saw_time==0?'已离开':date('Y-m-d', $person->five_saw_time) }}</td>
                            <td>{{ $person->phone }}</td>
                            <td style="text-align: center">
                                <!--
                                    <a href="{{ url('person/'.$person->id) }}" target="_blank">查看</a>
                                    <a href="{{ url('person/'.$person->id.'/edit') }}" >编辑</a>
                                    -->
                                    <a href="javascript:;" class="modal_recover" data-id="{{$person->id}}" data-toggle="modal" data-action="{{ url('person/recover') }}" data-target="#recover_modal" title="还原"><i class="fa fa-undo" aria-hidden="true"></i></a>
                                    &nbsp;&nbsp;
                                    <a href="javascript:;" class="modal_destroy" data-id="{{$person->id}}" data-toggle="modal" data-action="{{ url('person/delete') }}"  data-target="#delete_modal" title="彻底删除"><i class="fa fa-times" aria-hidden="true" style="color:darkred"></i></a>
                                    <!--
                                    <a href="javascript:;" data-toggle="modal" data-action="{{ url('person/'.$person->id) }}" data-target="#delete_modal">删除</a>
                                  -->
                            </td>
                          </tr>
                          @endforeach
                        </tbody>
                      </table>
                    <div class="text-right" style="margin:10px 0">
                                {{ $persons->appends([
                                    'action' => $action,
                                    'keyword' => $keyword,
                                    'is_the_city' => $is_the_city,
                                     'start_time' => $start_time,
                                     'end_time' => $end_time,
                                     'per_page' => $per_page
                                 ])->links() }}
                    </div>

            @else
                <p style="text-align:center;border:1px solid #ccc;border-radius: 5px;padding:10px;font-size:14px">回收站是空的</p>
                @endif
                </div>
            </div>
@endsection

@section("modal")
    <div class="modal fade" tabindex="-1" role="dialog" id="delete_modal">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">彻底删除</h4>
                </div>
                <div class="modal-body">
                    <p class="text-center">确定彻底删除吗?</p>
                </div>
                <div class="modal-footer">
                    <form action="{{url('person/destroy')}}" method="POST" style="display: inline;" id="model_form1">
                        {{ method_field('DELETE') }}
                        {{ csrf_field() }}
                        <input type="hidden" name="id" id="destroy_id" value="">
                        <button type="submit" class="btn btn-primary">是</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">否</button>

                    </form>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->

    <div class="modal fade" tabindex="-1" role="dialog" id="destroy_all_modal">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">清空回收站</h4>
                </div>
                <div class="modal-body">
                    <p class="text-center">确认清空回收站吗?</p>
                </div>
                <div class="modal-footer">
                    <form action="{{url('person/destroyAll')}}" method="POST" style="display: inline;" id="model_form2">
                        {{ csrf_field() }}
                        <button type="submit" class="btn btn-primary">是</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">否</button>

                    </form>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->


    <div class="modal fade" tabindex="-1" role="dialog" id="recover_modal">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">还原</h4>
                </div>
                <div class="modal-body">
                    <p class="text-center">确定还原吗?</p>
                </div>
                <div class="modal-footer">
                    <form method="POST" action="{{url('person/recover')}}" style="display:inline" id="model_form3">
                        {{ csrf_field() }}
                        <input type="hidden" name="id" id="recover_id" value="">
                        <button type="submit" class="btn btn-primary">是</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">否</button>

                    </form>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
@endsection

@section('script')
    <script src="{{ asset('plugin/datepicker/js/foundation-datepicker.js') }}"></script>
    <script src="{{ asset('plugin/datepicker/js/locales/foundation-datepicker.zh-CN.js') }}"></script>

<script>
  $(function(){
    $('#delete_button,#recover_button').click(function(){
        var ids = [];
        $("input[name='ids']").each(function() {
            if ($(this).prop('checked') == true) {
                ids.push($(this).val());
            }
        });
        ids = ids.join(",");
        $('#destroy_id').val(ids);
        $('#recover_id').val(ids);
        console.log(ids);
        if (ids == '') {
            alert('请至少选择一个人员');
            return false;
        }
    });
    $('#select_all').change(function(){
      //alert($(this).prop("checked"));
      $("input[name='ids']").prop("checked", $(this).prop("checked"));
        var ids = [];
        $("input[name='ids']").each(function() {
            if ($(this).prop('checked') == true) {
                ids.push($(this).val());
            }
        });
        ids = ids.join(",");
        //alert(ids);
       // $('#batch_delete').attr("data-action", "{{ url('person') }}/" + ids);
        $('#destroy_id').val(ids);
        $('#recover_id').val(ids);
    });
      $("input[name='ids']").change(function(){
          var ids = [];
          $("input[name='ids']").each(function() {
              if ($(this).prop('checked') == true) {
                  ids.push($(this).val());
              }
          });
          ids = ids.join(",");
          //alert(ids);
         // $('#batch_delete').attr("data-action", "{{ url('person') }}/" + ids);
          $('#destroy_id').val(ids);
          $('#recover_id').val(ids);
      });
      $('.modal_destroy').click(function(){
          var id = $(this).attr("data-id");
          $('#destroy_id').val(id);
      });

      $('.modal_recover').click(function(){
          var id = $(this).attr("data-id");
          $('#recover_id').val(id);
      });
  });

  $('#destroy_modal').on('show.bs.modal', function (event) {

      var button = $(event.relatedTarget) // Button that triggered the modal
      var action = button.data('action') // Extract info from data-* attributes

      var modal = $(this)
      modal.find('form').attr('action', action);
  });

  $('#recover_modal').on('show.bs.modal', function (event) {

      var button = $(event.relatedTarget) // Button that triggered the modal
      var action = button.data('action') // Extract info from data-* attributes

      var modal = $(this)
      modal.find('form').attr('action', action);
  });
</script>



    <script>
        $(function () {
            $('#per_page').change(function(){
                var per_page = $(this).val();
                //var url =   '?@foreach ($filter as $k => $v){{$k}}={{$v}}&@endforeach';
                var url = '?';
                window.location.href = '{{ url('person/recycleIndex') }}' + url + 'per_page=' + per_page;
            });
        });
    </script>


@endsection
